// Learn cc.Class:
//  - https://docs.cocos.com/creator/manual/en/scripting/class.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

cc.Class({
    extends: cc.Component,

    properties: {
		canvas:{
			default:null,
			type:cc.Node
		},
		logo:{
			default:null,
			type:cc.Node
		},
		btn1:{
			default:null,
			type:cc.Node
		},
		btn2:{
			default:null,
			type:cc.Node
		},
		btn3:{
			default:null,
			type:cc.Node
		}
    },


    onLoad () {
		
		this.btn1.active = false;
		this.btn2.active = false;
		this.btn3.active = false;
		
		this.canvas.opacity =0;
		
		this.canvas.runAction(cc.fadeIn(1));
		
		this.logo.runAction(cc.repeatForever(cc.sequence(cc.moveBy(1.5,0,20),cc.moveBy(1.5,0,-20))));
		
		wx.cloud.init({
			// 此处请填入环境 ID, 环境 ID 可打开云控制台查看
			env: 'wxxxl-lzhql',
			traceUser: true,
		})
		
		console.log("init over");
		
		if(CC_WECHATGAME){
			
			var self = this;
			
			wx.cloud.callFunction({
			// 云函数名称
			name: 'getChapterConfig',
			// 传给云函数的参数
			data: {},
			success: function(res) {
				console.log("get cloud config ");
				console.log(res.result.data);
				//self.chapterConfig = res.result.data;
				
				cc.sys.localStorage.setItem("CHAPTERCONFIG",res.result.data);
				
				self.btn1.active = true;
				self.btn2.active = true;
				self.btn3.active = true;
				
			},
				fail: console.error
			})
			
		}else{
			
			this.btn1.active = true;
			this.btn2.active = true;
			this.btn3.active = true;
			
		}
		
	},

   
});
